package com.example.myapplication

import android.content.Intent
import android.os.Bundle
import com.google.android.material.tabs.TabLayout
import androidx.appcompat.app.AppCompatActivity
import com.example.total.R
import com.example.total.databinding.ActivityMain2Binding

class MainActivity2 : AppCompatActivity() {

    private lateinit var binding: ActivityMain2Binding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main2)
        //点击主页tab
        findViewById<TabLayout>(R.id.tabs_main).addOnTabSelectedListener(object: TabLayout.OnTabSelectedListener {
            override fun onTabSelected(tab: TabLayout.Tab) {
                // 当选择“主页”标签时跳转到MainActivity2
                if (tab.position == 0) {
                    val intent = Intent(this@MainActivity2, MainActivity2::class.java)
                    startActivity(intent)
                }
            }

            override fun onTabUnselected(tab: TabLayout.Tab) {
                // 取消选中时不需要处理
            }

            override fun onTabReselected(tab: TabLayout.Tab) {
                // 再次选中时不需要处理
            }
        })

        //点击我的tab
        findViewById<TabLayout>(R.id.tabs_my).addOnTabSelectedListener(object: TabLayout.OnTabSelectedListener {
            override fun onTabSelected(tab: TabLayout.Tab) {
                // 当选择“我的”标签时跳转到Activity_My
                if (tab.position == 0) {
                    val intent = Intent(this@MainActivity2, Activity_My::class.java)
                    startActivity(intent)
                }
            }

            override fun onTabUnselected(tab: TabLayout.Tab) {
                // 取消选中时不需要处理
            }

            override fun onTabReselected(tab: TabLayout.Tab) {
                // 再次选中时不需要处理
            }
        })
}}